package com.lyf.scm.plan.api.controller;

import com.lyf.scm.plan.api.dto.BaseAreaInfoDTO;
import com.lyf.scm.plan.api.dto.BaseSkuInfoDTO;
import com.lyf.scm.plan.api.dto.UnitRateQueryDTO;
import com.lyf.scm.plan.domain.remote.basedata.dto.ChannelDTO;
import com.lyf.scm.plan.domain.remote.basedata.dto.StoreDTO;
import com.lyf.scm.plan.domain.remote.item.dto.SkuPriceDTO;
import com.lyf.scm.plan.domain.remote.item.dto.SkuUnitDTO;
import com.lyf.scm.plan.domain.service.RedisCacheService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 大数据redis缓存
 *
 * @author wangchlei
 * @date 2020/09/20
 */

@RomeController
@RequestMapping("/api/v1/redisCache")
public class RedisCacheController {
    @Resource
    private RedisCacheService redisCacheService;

    /**
     * 清空门店缓存
     */
    @GetMapping("stores")
    public Response deleteStores() {
        redisCacheService.deleteStores();
        return Response.builderSuccess(null);
    }

    /**
     * 清空门店缓存
     */
    @GetMapping("directStores")
    public Response deleteDirectStores() {
        redisCacheService.deleteDirectStores();
        return Response.builderSuccess(null);
    }

    @PostMapping("channel")
    public Response<Map<String, ChannelDTO>> getAllChannelInfo() {
        return Response.builderSuccess(redisCacheService.getAllChannelInfo());
    }


    @PostMapping("store")
    public Response<Map<String, StoreDTO>> getStoreInfoByCodes(@RequestBody List<String> codes) {
        return Response.builderSuccess(redisCacheService.getStoreInfoByCodes(codes));
    }

    @PostMapping("price")
    public Response<Map<String, BigDecimal>> getSkuAveragePrice(@RequestBody List<SkuPriceDTO> skuPriceDTOs) {
        return Response.builderSuccess(redisCacheService.getSkuAveragePrice(skuPriceDTOs));
    }

    @PostMapping("sku")
    public Response<Map<String, BaseSkuInfoDTO>> getCategoryInfoBySkuCodes(@RequestBody List<String> skuCodes) {
        return Response.builderSuccess(redisCacheService.getCategoryInfoBySkuCodes(skuCodes));
    }

    @PostMapping("unit")
    public Response<Map<String, SkuUnitDTO>> getUnitConversionRatio(@RequestBody List<UnitRateQueryDTO> unitRateQueryDTOs) {
        return Response.builderSuccess(redisCacheService.getUnitConversionRatio(unitRateQueryDTOs));
    }

    @PostMapping("areaInfo")
    public Response<Map<String, BaseAreaInfoDTO>> getAreaInfo(@RequestBody List<String> codes, @RequestParam("type") Integer type) {
        return Response.builderSuccess(redisCacheService.getAreaInfo(codes,type));
    }

    @PostMapping("deliverWarehouse")
    public Response<Map<String, StoreDTO>> getDeliverWarehouse() {
        return Response.builderSuccess(redisCacheService.getDeliverWarehouse());
    }
}
